<template>
  <view class="resetHeadPortrait">
    <echoCropper ref="aechoCropper"></echoCropper>
  </view>
</template>

<script>
import EchoCropper from '../../components/echo-cropper/echo-cropper'

export default {
  name: "headPortrait",
  components: {
    EchoCropper,
  },
  data() {
    return {
      src: null,
      type: null
    };
  },
  mounted(e) {
  },
  methods: {
    /**
     * 加载
     */
    async afterLoad(e){
      this.type = e.type
      this.$refs.aechoCropper.imageSrc = e.src
      this.$refs.aechoCropper.loadImage()
    },

    /**
     * 上传头衔
     * @param e
     */
    onNavigationBarButtonTap(e) {
      let self = this
      self.$refs.aechoCropper.getImageInfo().then(res => {
        switch (self.type) {
          case "updateHeadAvatar":
            self.$api.updateAvatar({
              files: [{
                name: "avatarFile",
                uri: res.file
              }],
              formData: {}
            }, {
              loading: true,
              loadingLabel: "处理中.."
            }).then(async (res) => {
              await self.refreshUserInfo()
              uni.navigateBack()
            })
            break
        }
      })
    }
  }
}
</script>

<style scoped>
.resetHeadPortrait {
  width: 100%;
}
</style>
